import type { IPublicTypeProjectSchema, ResultDir } from '@alilc/lowcode-types';
import standalone from './standaloneRun';

interface FlattenFile {
  /**
   * 文件路径
   */
  pathName: string;

  /**
   * 文件内容
   */
  content: string | Buffer;
}

export const DEFAULT_TIMEOUT_IN_MS = 60 * 1000;


export type Result = ResultDir | FlattenFile[];

export async function generateCode(options: {
  solution: 'icejs' | 'rax';
  schema: IPublicTypeProjectSchema;
  flattenResult?: boolean;
  workerJsUrl?: string;
  timeoutInMs?: number;
}): Promise<Result> {
  return new Promise(async(resolve, reject) => {
    const result: any = await standalone.run({
      solution: options.solution,
      schema: options.schema,
      flattenResult: options.flattenResult,
    });
    resolve(result);
  });
}